package com.zhoug.zmui.menu;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.zhoug.zmui.R;
import com.zhoug.zmui.ZMUIAnimations;
import com.zhoug.zmui.popup.ZMUIBasePopupWindow;

import java.util.List;

import androidx.core.content.ContextCompat;

/**
 * 多级菜单
 * @Author 35574
 * @Date 2020/8/13
 * @Description
 */
public class ZMUIMultiMenuPopupWindow extends ZMUIBasePopupWindow {
    private ZMUIMultiMenuView mMenuView;
    private View anchor;
    public ZMUIMultiMenuPopupWindow(Context context) {
        this(context, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    }

    public ZMUIMultiMenuPopupWindow(Context context, int width, int height) {
        super(context, width, height);
        setBackgroundDrawable( ContextCompat.getDrawable(context,R.drawable.zmui_card_bottom));
        setAnimationStyle(ZMUIAnimations.ANIM_ANCHOR_DOWN);
        init();
    }

    private void init() {
        View root = LayoutInflater.from(getContext()).inflate(R.layout.zmui_multi_menu_dialog, null);
        mMenuView = root.findViewById(R.id.menuView);
        setContentView(root);
    }

    public void setSelectColor(int selectColor) {
        mMenuView.setSelectColor(selectColor);
    }

    public List<? extends Menu> getMenus() {
        return mMenuView.getMenus();
    }

    public void setMenus(List<? extends Menu> menus) {
        mMenuView.setMenus(menus);
    }

    public void notifyDataSetChanged() {
        mMenuView.notifyDataSetChanged();
    }

    public ZMUIMultiMenuView.Callback getCallback() {
        return mMenuView.getCallback();
    }

    public void setCallback(ZMUIMultiMenuView.Callback callback) {
        mMenuView.setCallback(callback);
    }

    public void setAnchor(View anchor) {
        this.anchor = anchor;
    }

    public void show(){
        if(anchor==null){
            throw new NullPointerException("anchor is null please invoke setAnchor() before");
        }
        showAsDropDown(anchor);
    }

}
